{% extends "ordersapp/base.html" %}
{% load static %}
{% load cache %}

{% block container %}
    {% include 'ordersapp/includes/inc__order_summary.html' %}
    <div class="order_form">
        <form method="post" enctype="multipart/form-data">
            {% csrf_token %}
            {{ form.as_p }}
            <table class="table">
                {{ orderitems.management_form }}
                {% for item_form in orderitems.forms %}
                    {% if forloop.first %}
                        <thead>
                        <tr>
                            {% for field in item_form.visible_fields %}
                                <th class="{% cycle 'td1' 'td2' 'td3' 'td4' %} order formset_td">
                                    {{ field.label|capfirst }}
                                </th>
                            {% endfor %}
                        </tr>
                        </thead>
                    {% endif %}
                    <tr class="formset_row">
                        {% for field in item_form.visible_fields %}
                            <td class="{% cycle 'td1' 'td2' 'td3' 'td4' %} order formset_td">
                                {% if forloop.first %}
                                    {% for hidden in item_form.hidden_fields %}
                                        {{ hidden }}
                                    {% endfor %}
                                {% endif %}
                                {{ field.errors.as_ul }}
                                {% if field.name == 'price' %}
                                    <span class="items-{{ forloop.parentloop.counter0 }}-price">
                                        {{ field.value|default:"0,00" }}
                                    </span> руб
                                {% else %}
                                    {% if field.name == 'product' %}
                                        {% cache 3600 itemform_product field.value %}
                                            {{ field }}
                                        {% endcache %}
                                    {% else %}
                                        {{ field }}
                                    {% endif %}
                                {% endif %}
                            </td>
                        {% endfor %}
                    </tr>
                {% endfor %}
            </table>
            <input type="submit" value="сохранить"
                   class="btn btn-default btn-round form-control last">
            {% include 'ordersapp/includes/inc__order_actions.html' %}
        </form>
    </div>
{% endblock %}